
	Ext.namespace("panel.widgets.chunks.grid.columns");
	
	panel.widgets.chunks.grid.columns.header_editable = [
		
		"&nbsp;", 
		"(<img src='/images/pixel.gif' class='icon_ display_ib icon_action_edit_small' align='absmiddle' ext:qtip='Click on cell to edit value'>)"
		
	].join("");
	
	panel.widgets.chunks.grid.columns.id = function(config) {
		
		var config = Ext.value(config, {});
		
		var column = {
			
			id        : Ext.value(config.id,         "id"),
			header    : Ext.value(config.header,     "ID"),          
			width     : Ext.value(config.width,      (!Ext.isSafari ? 40 : 45)),  
			sortable  : Ext.value(config.sortable,   true), 
			dataIndex : Ext.value(config.dataIndex, "id"),
			hidden    : Ext.value(config.hidden,     false),
			fixed     : Ext.value(config.fixed,      false),
			align     : "right",
			
			renderer: function(v, cell) {
				
				cell.css += " s_small fnt_mono ";
				
				return [
					"<font class='c_lgray x-unselectable'>",
					String.leftPad("", 5 - v.toString().length, "0"),
					"</font>",
					v, "&nbsp;"
				].join("");
				
			}
			
		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.eid = function(config) {
		
		var config = Ext.value(config, {});
		config.dataIndex = Ext.value(config.dataIndex, "eid");
		
		return panel.widgets.chunks.grid.columns.id(config);
		
	};
	
	panel.widgets.chunks.grid.columns.spacer = function(config) {
		
		var config = Ext.value(config, {});
		
		var column = {
			
			id     : "spacer",
			header : "&nbsp;",
			fixed  : true,
			sortable: false,
			renderer: Ext.value(config.renderer, function(v, cell, record) { 
				
				if( config.height ) {
					cell.css += " h_" + config.height + " "; }
				
				return ""; 
				
			})
			
		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.attribute = function(config) {
		
		var config = Ext.value(config, {});
		
		var column = {
			
			header    : config.header,          
			width     : config.width,   
			dataIndex : config.dataIndex,
			id        : Ext.value(config.id,         Ext.id()),
			sortable  : Ext.value(config.sortable,   true),
			fixed     : Ext.value(config.fixed,      false),
			hidden    : Ext.value(config.hidden,     false),
			
			renderer: config.renderer || function(v, cell, record) {
				
				cell.css += " white_space_normal_r ";

				if( !v ) {
					cell.css += " s_italic c_lgray "; }
				
				return v ? v : "NONE";
				
			}
			
		};
	
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.catalog = function(config) {
		
		var config = Ext.value(config, {});
		
		var column = {
			
			id        : "catalog",
			header    : Ext.value(config.header,     "Catalog"),          
			width     : Ext.value(config.width,      (!Ext.isSafari ? 40 : 45)),  
			sortable  : Ext.value(config.sortable,   true), 
			dataIndex : Ext.value(config.dataIndex, "catalog"),
			hidden    : Ext.value(config.hidden,     false),
			fixed     : Ext.value(config.fixed,      false),
			align     : "center"
						
		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.is_active = function(config) {
		
		var config = Ext.value(config, {});
		
		config.header   = Ext.value(config.header,   "Active?");
		config.editable = Ext.value(config.editable, false);
		config.headerShowEditable = Ext.value(config.headerShowEditable, config.editable);
		config.readOnly = Ext.value(config.readOnly, true);
		
		if( config.editable ) {
			config.readOnly = false; };
			
		if( config.headerShowEditable ) {
			config.header += "<br>" + panel.widgets.chunks.grid.columns.header_editable; }

		var column = new Ext.grid.CheckboxColumn({
			
			header    : config.header,          
			width     : Ext.value(config.width,      (!Ext.isSafari ? 55 : 60)),  
			sortable  : Ext.value(config.sortable,   true), 
			dataIndex : Ext.value(config.dataIndex, "is_active"),
			readOnly  : config.readOnly,
			hidden    : Ext.value(config.hidden,     false),
			fixed     : Ext.value(config.fixed,      false),
			hdCheckbox  :  Ext.value(config.hdCheckbox, false),
			align     : "center",
			
			clsOnChecked    : Ext.value(config.clsOnChecked,   "icon_on"),
			clsOnUnchecked  : Ext.value(config.clsOnUnchecked, "icon_off"),
			
			onChange        : Ext.value(config.onChange, undefined),
			
			getRenderParams : Ext.value(config.getRenderParams, function(v) {
				
				return {
					
					tooltip: v ? "This item is active" : "This item is not active"
				
				}
				
			})
			
		});
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.is_checked = function(config) {
		
		var config = Ext.value(config, {});

		var column = new Ext.grid.CheckboxColumn({
			
			header      : Ext.value(config.header,     "&nbsp;"),         
			width       : Ext.value(config.width,      30),  
			sortable    : Ext.value(config.sortable,   true), 
			dataIndex   : Ext.value(config.dataIndex, "is_checked"),
			readOnly    : Ext.value(config.readOnly,   false),
			hidden      : Ext.value(config.hidden,     false),
			hdCheckbox  :  Ext.value(config.hdCheckbox, true),
			hdOnChangeSuppress: true,
			menuDisabled : Ext.value(config.menuDisabled, false),
			fixed        : Ext.value(config.fixed,      false),
			indirect     : true,
			markChanges  : false,
			align        : "center",
			
			clsOnChecked    : Ext.value(config.clsOnChecked, undefined),
			clsOnUnchecked  : Ext.value(config.clsOnUnchecked, undefined),
			getRenderParams : Ext.value(config.getRenderParams, undefined),
			onChange        : Ext.value(config.onChange, undefined)
			
		});
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.is_checked_on_change_select_product_hierarchy = function(me, store, record, value, field, id, hooks) {
		
		var hooks = Ext.value(hooks, {});
		
		switch( record.data.etype ) {
		
		case "PC":
		case "P":
		case "PD":
			
			me.checkRecords(
				
				store.queryBy( function(r) { 
				
					return ( 
						
						// Parent match
						r.data.parents[record.data.uid] != undefined 
						
						&&
						
						// If match hook rule
						
						( (hooks.isCheckable instanceof Function) ? hooks.isCheckable(r) : true )
						
					);
					
				}), 
				value
				
			);
			
			break;
		
		case "PP":
			break;
			
		}	// switch
		
		if( !value ) {
			
			var f = function(record) {

				if( !record.data.parent ) {
					return; }
				
				var parent = store.find("uid", record.data.parent);
				
				if( parent == -1 ) {
					return; }
					
				var parent = store.getAt(parent);
				
				var checked = store.findBy( function(f) { 
					
					return (
						f.data.parent == record.data.parent && 
						f.data.is_checked
					);
					 
				} );
				
				if( checked != - 1 ) {
					return; }
					
				me.checkRecords([parent], false);
				
				f(parent);
				
			};
			
			f(record);
			
		}	// if
		
	};
	
	panel.widgets.chunks.grid.columns.yesno = function(config) {
		
		var config = Ext.value(config, {});
		
		config.clsOnChecked    = Ext.value(config.clsOnChecked    , "icon_yes");
		config.clsOnUnchecked  = Ext.value(config.clsOnUnchecked  , "icon_no");
		config.getRenderParams = Ext.value(config.getRenderParams , function(v) {
				
			return {
				tooltip: ( 
					v ? 
					"<font class='c_green s_bold'>YES</font>" : 
					"<font class='c_red s_bold'>NO</font>" 
				)
			}
			
		});

		return panel.widgets.chunks.grid.columns.is_active(config);
		
	};
	
	panel.widgets.chunks.grid.columns.title = function(config) {
		
		var config = Ext.value(config, {});
		config.dataIndices = Ext.value(config.dataIndices, {});
		config.dataIndices.is_active   = Ext.value(config.dataIndices.is_active, "is_active");
		config.dataIndices.is_modified = Ext.value(config.dataIndices.is_modified, "is_modified");
		
		var column = {
			
			id        : Ext.value(config.id,         "title"),
			header    : Ext.value(config.header,     "Title"),          
			width     : config.width,  
			sortable  : Ext.value(config.sortable,   true), 
			dataIndex : Ext.value(config.dataIndex,  "title"),
			hidden    : Ext.value(config.hidden,     false),
			fixed     : Ext.value(config.fixed,      false),
			
			renderer: config.renderer || function(v, cell, record) {
				
				cell.css += " white_space_normal_r fnt_size_main ";

				if( 
					record.data[config.dataIndices.is_active] != undefined && 
					!record.data[config.dataIndices.is_active] 
				) {
					
					cell.css += " c_red "; 
					
				}
									
				return v;
				
			}
			
		};
	
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.title_product = function(config) {
		
		var config = Ext.value(config, {});
		
		var column = {
			
			id        : Ext.value(config.id,         "title"),
			header    : Ext.value(config.header,     "Title"),          
			width     : Ext.value(config.width,      150),  
			sortable  : Ext.value(config.sortable,   true), 
			dataIndex : Ext.value(config.dataIndex,  "title"), 
			hidden    : Ext.value(config.hidden,     false),
			hierarchy : Ext.value(config.hierarchy,  false),
			fixed     : Ext.value(config.fixed,      false),
			
			renderer: config.renderer || function(v, cell, record) {
				
				if( !record.data.is_active ) {
					cell.css += " c_red "; }
					
				if( record.data.is_modified ) {
					cell.css += " x-grid3-dirty-cell "; }
				
				var rp = {};

				if( config.getRendererParams instanceof Function ) {

					var rp = Ext.value(config.getRendererParams(v, cell, record), {});
					
				}	// if
					
				var tpl = [];
					
				switch( record.data.etype ) {
					
				case "PC":
					
					if( config.hierarchy ) {
						cell.css += " s_bold ";	}
					
					tpl.push(
						"<div class='icon_ ",
						Ext.value(rp.icon, "icon_e_product_category"),
						" f_l' ext:qtip='Product category' /></div>"
					);
										
					break;
					
				case "P":
				
					tpl.push(
						"<div class='icon_ ",
						Ext.value(rp.icon, "icon_e_product"),
						" f_l' ext:qtip='Product' /></div>"
					);
				
					break;
										
				case "PD":
					
					tpl.push(
						"<div class='icon_ ",
						Ext.value(rp.icon, "icon_e_product_descriptor"),
						" f_l' ext:qtip='Product Pack' /></div>"
					);
					
					break;
										
				case "PP":
					
					tpl.push(
						"<div class='icon_ ",
						Ext.value(rp.icon, "icon_e_product_pack"),
						" f_l' ext:qtip='Product Pack Quantity' /></div>"
					);
					
					break;
												
				}	// switch
				
				if( 
					record.data.etype == "P" || 
					( config.renderProductTags && record.data.etype != "PC" ) 
				) {
					
					tpl.push(
						"<div ext:qtip='", record.data.tag_type, "' class='f_l icon_ icon_i-", record.data.tag_type.replace(" ", "_"), "'></div>",
						"<div ext:qtip='", record.data.tag_license, "' class='f_l icon_ icon_i-", record.data.tag_license.replace(" ", "_"), "'></div>"
					);
					
				}	// if
				
				tpl.push(
					"<div class='m_l15 white_space_normal' ",
					(rp.tooltip ? " ext:qtip='"  + rp.tooltip + "' " : ""),
					" >",
					"&nbsp;"
				);
				
				switch( record.data.etype ) {
				
				case "PP":
				
					tpl.push(
						"<font class='fnt_mono fnt_size_9_5pt s_bold'>", 
						String.leftPad(record.data.quantity, 3, "&nbsp;"), 
						"</font>&nbsp;x&nbsp;", v
					);
				
					break;
					
				default:
					tpl.push(v);
					break;
					
				}	// switch
				
				tpl.push("</div>");
				
				return tpl.join("");
				
			}

		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.title_asset = function(config) {
		
		var config = Ext.value(config, {});
		
		var column = {
			
			id        : Ext.value(config.id,         "title"),
			header    : Ext.value(config.header,     "Title"),          
			width     : Ext.value(config.width,      150),  
			sortable  : Ext.value(config.sortable,   true), 
			dataIndex : Ext.value(config.dataIndex,  "title"), 
			hidden    : Ext.value(config.hidden,     false),
			hierarchy : Ext.value(config.hierarchy,  false),
			fixed     : Ext.value(config.fixed,      false),
			
			renderer: config.renderer || function(v, cell, record) {
				
				if( !record.data.is_active ) {
					cell.css += " c_red "; }
					
				if( record.data.is_modified ) {
					cell.css += " x-grid3-dirty-cell "; }
				
				var rp = {};

				if( config.getRendererParams instanceof Function ) {

					var rp = Ext.value(config.getRendererParams(v, cell, record), {});
					
				}	// if
					
				var tpl = [];
					
				switch( record.data.etype ) {
					
				case "G":
					
					if( config.hierarchy ) {
						cell.css += " s_bold ";	}
					
					tpl.push(
						"<div class='icon_ ",
						Ext.value(rp.icon, "icon_e_global"),
						" f_l' ext:qtip='Global' /></div>"
					);
										
					break;
					
				case "CATALOG":
				
					if( config.hierarchy ) {
						cell.css += " s_bold ";	}
				
					tpl.push(
						"<div class='icon_ ",
						Ext.value(rp.icon, "icon_e_catalog"),
						" f_l' ext:qtip='Catalog' /></div>"
					);
				
					break;
					
				case "P":
				
					tpl.push(
						"<div class='icon_ ",
						Ext.value(rp.icon, "icon_e_profile"),
						" f_l' ext:qtip='Profile' /></div>"
					);
				
					break;
										
				case "W":
					
					tpl.push(
						"<div class='icon_ ",
						Ext.value(rp.icon, "icon_e_website"),
						" f_l' ext:qtip='Website' /></div>"
					);
					
					break;
												
				}	// switch
				
				tpl.push(
					"<div class='m_l15 white_space_normal' ",
					(rp.tooltip ? " ext:qtip='"  + rp.tooltip + "' " : ""),
					" >",
					"&nbsp;"
				);
				
				
				switch( record.data.etype ) {
				
				case "W":
				
					if( config.url ) {
						
						tpl.push(
							"<a href='", record.data[config.url.dataIndex] ,"' target='_blank'>",
							v,
							"</a>"
						);
						
					} else {
				
						tpl.push(v);
						
					}	// if
						
					break;
					
				default:
					tpl.push(v);
					break;
					
				}
				
				tpl.push("</div>");
				
				return tpl.join("");
				
			}

		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.number = function(config) {
		
		var config = Ext.value(config, {});
		
		config.header   = Ext.value(config.header,  "Number");
		config.editable = Ext.value(config.editable, false);
		config.headerShowEditable = Ext.value(config.headerShowEditable, config.editable);
		config.percent = Ext.value(config.percent, false);
		config.color = Ext.value(config.color, false);
		config.type  = Ext.value(config.type, "number");
		
		if( config.headerShowEditable ) {
			config.header += "<br>" + panel.widgets.chunks.grid.columns.header_editable; }
		
		var column = {
			
			header    : config.header,          
			width     : Ext.value(config.width,      65),  
			sortable  : Ext.value(config.sortable,   true), 
			dataIndex : config.dataIndex, 
			hidden    : Ext.value(config.hidden,     false),
			editable  : Ext.value(config.editable,   config.editor ? true : false),
			editor    : Ext.value(config.editor,     undefined),
			align     : "center",
			fixed     : Ext.value(config.fixed,      false),
			
			renderer:  config.renderer || function(v, cell, record) {
				
				cell.css += " fnt_size_9pt a_right ";
				
				if( config.color ) {
					cell.css += ( v > 0 ) ? " c_green " : " c_red "; }
				
				if( config.highlight ) {
					cell.css += " s_te s_bold "; }
				
				if( config.zeroText && v == 0 ) {
					
					cell.css += " a_center ";
					return config.zeroText; 
					
				} else {
					
					
					
					switch( config.type ) {
						
					case "price":
						cell.css += " a_center ";
						return [ ( v < 0 ? "-" : "" ), "$", new Number(v).abs() ].join("");
						break;	
						
					case "number":
						cell.css += " a_right ";
						return v;
						break;
						
					case "percent":
						cell.css += " a_right ";
						return [ v, "%" ].join("");
						break;
						
					}	// switch
										
				}	// if
				
			}
			
		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.quantity = function(config) {
		
		var config = Ext.value(config, {});
		
		config.header    = Ext.value(config.header, "Quantity");
		config.dataIndex = Ext.value(config.dataIndex, "quantity");
		
		return panel.widgets.chunks.grid.columns.number(config);
		
	};
	
	panel.widgets.chunks.grid.columns.price = function(config) {
		
		var config = Ext.value(config, {});
		
		config.header   = Ext.value(config.header,  "Price");
		config.editable = Ext.value(config.editable, false);
		config.headerShowEditable = Ext.value(config.headerShowEditable, config.editable);
		
		if( config.headerShowEditable ) {
			config.header += "<br>" + panel.widgets.chunks.grid.columns.header_editable; }
		
		var column = {
			
			header    : config.header,          
			width     : Ext.value(config.width,      65),  
			sortable  : Ext.value(config.sortable,   true), 
			dataIndex : Ext.value(config.dataIndex,  "price"), 
			hidden    : Ext.value(config.hidden,     false),
			editable  : Ext.value(config.editable,   config.editor ? true : false),
			editor    : Ext.value(config.editor,     undefined),
			align     : "center",
			fixed     : Ext.value(config.fixed,      false),
			
			renderer:  config.renderer || function(v, cell, record) {
				
				if( config.checkETYPE && record.data.etype != "PP" ) {
					return ""; }
				
				cell.css += " fnt_size_9pt a_right ";
				cell.css += ( v > 0 ) ? " c_green " : " c_red ";
				
				if( config.highlight ) {
					cell.css += " s_te s_bold ";
				}
				
				if( config.zeroText && v == 0 ) {
					
					cell.css += " a_center ";
					return config.zeroText; 
					
				} else {
					
					cell.css += " a_right ";
					return [ ( v < 0 ? "-" : "" ), "$", new Number(v).abs() ].join("");
					
				}	// if
				
			}
			
		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.datetime = function(config) {
		
		var config = Ext.value(config, {});
		
		if( !config.format ) {
			config.format = "Y-m-d<br>h:i:s"; }
		
		if( config.humanReadable ) {
			config.format = "M j, Y<br>g:i a"; } 
		
		var column = {
			
			header    : config.header,          
			width     : Ext.value(config.width, 70),  
			sortable  : Ext.value(config.sortable, true), 
			dataIndex : config.dataIndex, 
			hidden    : Ext.value(config.hidden,     false),
			fixed     : Ext.value(config.fixed,      false),
			align     : "center",
			
			renderer: config.renderer || function(v, cell) {
					
				if( !config.humanReadable ) {
					cell.css += " s_small "; }
				
				if( !v && config.emptyText ) {
				
					cell.css += " s_italic c_gray ";
					return config.emptyText; 
					
				} else {
				
					return v.format(config.format);
					
				}
									
			}
			
		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.date = function(config) {
		
		var config = Ext.value(config, {});
		
		if( !config.format ) {
			config.format = "Y-m-d"; }
		
		if( config.humanReadable ) {
			config.format = "F j, Y"; } 
		
		var column = {
			
			header    : Ext.value(config.header,    "Date"),         
			width     : Ext.value(config.width,     70),  
			sortable  : Ext.value(config.sortable,  true), 
			dataIndex : Ext.value(config.dataIndex, "date"),
			hidden    : Ext.value(config.hidden,    false),
			fixed     : Ext.value(config.fixed,     false),
			align     : "center",
			
			renderer: config.renderer || function(v, cell) {
					
				if( !config.humanReadable ) {
					cell.css += " s_small "; }
				
				if( !v && config.emptyText ) {
				
					cell.css += " s_italic c_gray ";
					return config.emptyText; 
					
				} else {
					
					return v.format(config.format);
					
				}
									
			}
			
		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.time = function(config) {
		
		var config = Ext.value(config, {});
		
		var column = {
			
			header    : Ext.value(config.header,    "Time"),         
			width     : Ext.value(config.width,     70),  
			sortable  : Ext.value(config.sortable,  true), 
			dataIndex : Ext.value(config.dataIndex, "time"),
			hidden    : Ext.value(config.hidden,    false),
			align     : "center",
			renderer  : Ext.value(config.renderer, undefined),
			fixed     : Ext.value(config.fixed,      false)
			
		};
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.compare = function(config) {
		
		var config = Ext.value(config, {});
		
		var column = {
			
			header    : config.header,
			align     : "center",
			dataIndex : config.dataIndexA,
			width     : Ext.value(config.width, undefined),
			fixed     : Ext.value(config.fixed,      false),
			renderer  : function(v, cell, record) {
				
				switch( config.type ) {
				
				case "price":
					var symbol = "$";
					break;
				
				default:
					var symbol = "";
					break;
				
				}	// switch
				
				if( 
					(config.triggerIndex && record.data[config.triggerIndex]) || 
					config.triggerIndex == undefined 
				) {
				
					cell.css += "a_left";
					
					switch( true ) {
						
					case ( record.data[config.dataIndexA] > record.data[config.dataIndexB] ):
						var diff = "up"; break;
						
					case ( record.data[config.dataIndexA] < record.data[config.dataIndexB] ):
						var diff = "down"; break;
						
					default:
						var diff = "eq"; break;
						
					}	// switch
					
					return [
						
						"<img src='/icon/value_" + diff + ".png' align='absmiddle'>",
						"<span class='", 
							(( record.data[config.dataIndexA] > 0 ) ? "c_green" : "c_red"), 
							" p_lr2 s_bold fnt_size_9pt'>",
							(( record.data[config.dataIndexA] >= 0 ) ? "" : "-" ),
							symbol, 
							record.data[config.dataIndexA].toFloat().abs(),
						"</span>",
						"/",
						"<span class='p_lr2 c_gray'>(", 
							(( record.data[config.dataIndexB] >= 0 ) ? "" : "-" ),
							symbol, 
							record.data[config.dataIndexB].toFloat().abs(),
						")</span>"
						
					].join("");
					
				} else {
					
					cell.css += " fnt_size_9pt ";
					cell.css += (( record.data.config_price > 0 ) ? "c_green" : "c_red");
					
					return [
						
						(( record.data[config.dataIndexB] >= 0 ) ? "" : "-" ),
						symbol, 
						record.data[config.dataIndexB].toFloat().abs()
						 
					].join("");
					
				}	// if
				
			}	// if			
			
		};
		
		if( config.editor ) {
			
			column.header += panel.widgets.chunks.grid.columns.header_editable;
			column.editor = config.editor;
			
		};
		
		return column;	
		
	};
	
	panel.widgets.chunks.grid.columns.created_at = function() {
		
		return panel.widgets.chunks.grid.columns.datetime({
			
			header:    "Created",          
			dataIndex: "created_at"
			
		});
		
	};
	
	panel.widgets.chunks.grid.columns.updated_at = function() {
		
		return panel.widgets.chunks.grid.columns.datetime({
			
			header:    "Updated",          
			dataIndex: "updated_at"
			
		});
		
	};
	
	panel.widgets.chunks.grid.columns.is_filtered = function(config) {
		
		var config = Ext.value(config, {});

		config.header = [
			"<img src='/icon/filters_collection.png' ext:qtip='Is blocked by NOBRAND filters?'>",
			"<img src='/icon/e_blocked.png' ext:qtip='Is blocked by NOBRAND filters?'>"
		].join("");          

		config.dataIndex      = Ext.value(config.dataIndex, "is_filtered");
		config.clsOnChecked   = "icon_e_blocked";
		config.clsOnUnchecked = "icon_e_allowed_trans";
		
		config.getRenderParams = function(v) {
				
			return {
				tooltip: v ? 
					"This item is blocked by NOBRAND filters" : 
					"This item is not blocked by NOBRAND filters"
			}
			
		};
		
		return panel.widgets.chunks.grid.columns.is_active(config);
		
	};	
	
	/**
	 * Calculon:
	**/
	/* {% if isset($template.calculon) %} */
	
	panel.widgets.chunks.grid.columns.calculon = {};
	
	panel.widgets.chunks.grid.columns.calculon.modifier_type = function(config) {
		
		var column = {
			
			header: [
				
				"Modifier<br>Type",
				"&nbsp;(<img src='/icon/action_edit_small.png' align='absmiddle'>)"
				
			].join(""),
					
			dataIndex: "modifier_type",
			width: 70,
			align: "center",
			renderer: function(v, cell, record) {
						
				cell.css += " mouse_pointer bg_lllgray h_25 ";
						
				switch(record.data.modifier_type) {
							
				case "NONE":
					cell.attr += " ext:qtip='Do not apply any modification.' ";
					break;
						
				case "FIXED":
					cell.attr += "ext:qtip='Set a fixed value.'";
					break;
						
				case "PERCENT":
					cell.attr += " ext:qtip='Apply a percent modifier.' ";
					break;
						
				case "NUMBER":
					cell.attr += " ext:qtip='Apply a numeric modifier.' ";
					break;
							
				}	// switch
						
				return v;
						
			}
			
		};
		
		column.editor = new Ext.form.ComboBox({
					
			lazyInit       : false,
			lazyRender     : false,
			editable       : true,
			allowBlank     : false,
			resizable      : false,
			typeAhead      : false,
			forceSelection : true,
			selectOnFocus  : true,
			
			triggerAction  : "all",
			mode           : "local",
			
			displayField   : "id",
			valueField     : "id",
							
			maskRe: /^[a-zA-Z]+$/,
			
			store: new Ext.data.JsonStore({
				
				id: "id",
				
				fields: [
					
					{ name: "id", type: "string" }
					
				],
				
				data: {% $template.calculon.modifier_types|@json_encode %}
				
			}),
			
			validationDelay: 50,
			
			validator: function(v) {
				
				if( this.store.findBy( function(rec, id) { return ( rec.data.id == v ); } ) != -1 ) {
					return true; }	

			}
								
		});
		
		return column;
		
	};
	
	panel.widgets.chunks.grid.columns.calculon.modifier_value = function(config) {
		
		var column = {
					
			header: [
				
				"Modifier<br>Value",
				"&nbsp;(<img src='/icon/action_edit_small.png' align='absmiddle'>)"
				
			].join(""),
			
			dataIndex: "modifier_value",
			width: 70,
					
			renderer: function(v, cell, record) {
				
				cell.css += " fnt_size_9pt bg_lllgray h_25 ";
				
				record.data.modifier_value = new Number(record.data.modifier_value);
				
				switch( true ) {
					
				case (record.data.modifier_value >= 0): var sign = (record.data.modifier_type == "FIXED" ? "" : "+");  break;
				case (record.data.modifier_value < 0):  var sign = "-"; break;
					
				}	// switch
				
				cell.css  += ((v <= 0) ? " c_red " : " c_green ");						
				
				switch(record.data.modifier_type) {
					
				case "NONE":
				
					cell.css  += " c_lgray ";
					cell.attr += " ext:qtip='Do not apply any modification.' ";
					return "N/A";
					
					break;
					
				case "FIXED":
				
					cell.css  += " mouse_pointer ";
					cell.attr += " ext:qtip='Set a fixed value.' ";
					
					return [ sign, "$", record.data.modifier_value.abs() ].join("");
				
					break;
					
				case "PERCENT":
				
					cell.css  += " mouse_pointer ";
					cell.attr += " ext:qtip='Apply a percent discount.' ";
					
					return [ sign, record.data.modifier_value.abs(), "%" ].join("");
				
					break;
					
				case "NUMBER":
				
					cell.css  += " mouse_pointer ";
					cell.attr += " ext:qtip='Apply a numeric discount.' ";
					
					return [ sign, "$", record.data.modifier_value.abs() ].join("");
				
					break;
					
				}
				
			}
			
		};
		
		config.editor = Ext.value(config.editor, {});
				
		column.editor = new Ext.form.TextField({
						
			allowBlank: false,
			maxLength: 4,
			minLength: 1,
			maskRe: /^[\-\+0-9]+$/,
			enableKeyEvents: true,
			validationDelay: 50,
			
			validator: function(v) {
				
				var grid     = config.editor.grid();
				var calculon = config.editor.calculon();
				
				if( !grid.activeEditor ) {
					return false; }
				
				var record = grid.activeEditor.record;
				
				switch( record.data.modifier_type ) {
				
				case "NONE":							
				case "FIXED":
				case "NUMBER":
				case "PERCENT":
					
					try {
						
						var result = calculon.getResultValue({
							
							modifier_type  : record.data.modifier_type,
							modifier_value : v
						
						}, true);
						
					} catch( e ) { return e; }
					
					return true;
						
					break;
					
				}

			}
			
		});
		
		return panel.widgets.chunks.grid.columns.number(column);
		
	};
	
	/* {% /if %}*/
